<?php get_instance()->view('common/header');?>
<div class="page-container home">
    <?php get_instance()->view('common/sidebar');?>
    <div class="page-content-wrapper">
        <div class="page-content">
            <div class="row">
                <div class="col-md-12">
                    <!-- BEGIN PAGE TITLE & BREADCRUMB-->
                    <h3 class="page-title"> <?php echo $title ?> </h3>
                    <ul class="page-breadcrumb breadcrumb">
                        <li><i class="fa fa-home"></i><a href="javascript:void(0);"><?php echo $title ?> </a></li>
                    </ul>
                    <!-- END PAGE TITLE & BREADCRUMB-->
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <div class="portlet">
                        <div class="portlet-body">
                            <div class="table-container">
                                <div class="table-actions-wrapper"> <span> </span>
                                    <?php if(adminAuthority('home-add', 'product')):?>
                                        <a class="btn btn-sm blue add" href="<?php echo getUrl('product/home/add')?>"><i class="fa fa-plus"></i> 新增</a>
                                        <a class="btn btn-sm blue confirm"  attr="1" href="javascript:void(0)"><i class="fa fa-plus"></i> 批量上架</a>
                                        <a class="btn btn-sm red confirm"  attr="2" href="javascript:void(0)"><i class="fa fa-minus"></i> 批量下架</a>
                                    <?php endif;?>
                                </div>
                                <table class="table table-bordered table-hover" id="datatable">
                                    <thead>
                                    <tr role="row" class="heading">
                                        <th width="50px" class="table-checkbox">
                                            <input type="checkbox" class="group-checkable" data-set="#sample_1 .checkboxes"/>
                                        </th>
                                        <th width="4%"> 图标 </th>
                                        <th width="10%" sort="false">商家名称</th>
                                        <th width="21%"> 商品名称 </th>
                                       <th width="9%" sort="false">分类名称</th>
                                       <th width="10%" sort="false">价格</th>
                                       <th width="6%" sort="false">销量</th>
                                       <th width="6%" sort="false">库存</th>
                                        <th width="10%" sort="false">创建时间</th>
                                        <th width="9%" sort="false">状态</th>
                                        <th width="15%" sort="false">操作</th>
                                    </tr>
                                    <tr>
                                        <th></th>
                                        <th></th>
                                        <th><input class="form-control form-filter input-sm" name="merchant_name" type="text"></th>
                                        <th><input class="form-control form-filter input-sm" name="name" type="text"></th>
                                        <th>
                                            <select name="parent_id" id="category" class="form-control form-filter input-sm">
                                                <option value="" selected="selected">所有</option>
                                                <?php foreach ($category as $k => $v):?>
                                                    <option value="<?php echo $v['id'];?>"><?php echo $v['cat_name'];?></option>
                                                <?php endforeach;?>
                                            </select>
                                            <select name="category_id" id="two" class="form-control form-filter input-sm">
                                                <option value="" selected="selected">所有</option>
                                            </select>
                                            <select name="custom_category_id" id="custom" class="form-control form-filter input-sm">
                                                <option value="" selected="selected">所有</option>
                                            </select>
                                            <script type="text/javascript">
                                                $(function () {
                                                    var url = "<?php echo getUrl('common/getCategoryList')?>";
                                                    $("select").select2();

                                                    // 一级
                                                    $('#category').live('change', function(){
                                                        var id=$(this).val();
                                                        if (id){
                                                            category(id);
                                                        }else{
                                                            $("#two").html("<option>所有</option>");
                                                            $("#custom").html("<option>所有</option>");
                                                            $("select").select2();
                                                        }

                                                    });

                                                    // 二级
                                                    $('#two').live('change', function(){
                                                        var id = $(this).val();
                                                        if (id) {
                                                            custom(id);
                                                        }else{
                                                            $("#custom").html("<option>所有</option>");
                                                            $("select").select2();
                                                        }
                                                    });

                                                    //省市联动
                                                    function category(id){
                                                        if(id != ''){
                                                            $.post(url,{parent_id:id,type:1},function(re){
                                                                $("#two").find("option").remove();
                                                                var two = "<option value=''>请选择</option>";
                                                                $.each( re, function(i,item){
                                                                    two += "<option value='" + item['id'] + "'>" + item['cat_name'] + "</option>";
                                                                });
                                                                $("#two").html(two);
                                                                $("select").select2();
                                                            },'json');
                                                            $("#custom").html("<option>请选择</option>");
                                                            $("select").select2();
                                                        }
                                                    }

                                                    //市县联动
                                                    function custom(id){
                                                        if(id != ''){
                                                            $.post(url,{parent_id:id,type:2},function(re){
                                                                $("#id").find("option").remove();
                                                                var custom = "<option>请选择</option>";
                                                                $.each( re, function(i,item){
                                                                    custom += "<option value='" + item['id'] + "'>" + item['cat_name'] + "</option>";
                                                                });
                                                                $("#custom").html(custom);
                                                                $("select").select2();
                                                            },'json')
                                                        }
                                                    }
                                                });
                                            </script>
                                        </th>
                                        <th>
                                            <input class="form-control form-filter input-sm" name="goods_price" type="text" placeholder="价格"/>
                                        </th>
                                        <th></th>
                                        <th></th>
                                        <th>
                                            <div class="margin-bottom-5">
                                                <input class="form-control form-filter input-sm" name="pro_send_date_from" dp placeholder="大于等于" type="text">
                                            </div>
                                            <input class="form-control form-filter input-sm" name="pro_send_date_to" dp placeholder="小于等于" type="text">
                                        </th>
                                        <th>
                                            <select name="pro_status" class="form-control form-filter input-sm">
                                                <option value="" selected="selected">所有</option>
                                                <?php foreach ($status as $k => $v):?>
                                                <option value="<?php echo $k+1;?>"><?php echo $v;?></option>
                                                <?php endforeach;?>
                                            </select>
                                        </th>
                                        <th>
                                            <div class="btn-group">
                                                <a class="btn btn-xs filter-submit btn-default"><i class="fa fa-search"></i> 搜索</a>
                                                <button data-toggle="dropdown" class="btn btn-default dropdown-toggle btn-xs" type="button"><i class="fa fa-angle-down"></i></button>
                                                <ul role="menu" class="dropdown-menu pull-right">
                                                    <li><a href="javascript:void(0);" class="filter-cancel">重置</a></li>
                                                </ul>
                                            </div>
                                        </th>
                                    </tr>
                                    </thead>
                                    <tbody></tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 确认信息弹框 start-->
<div id="model-modal-msg" style="top: 20%;" class="modal fade modal_small hide" role="dialog" aria-labelledby="myModalLabel1" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                <h4 class="modal-title">确认信息</h4>
            </div>
            <form action="#" class="form-horizontal" id="model-form" method="post">
                <div class="modal-body">
                    <p id="model-msg"></p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn green save" id=""><i class="fa fa-save " ></i> 确定</button>
                </div>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function(){
        datatable_init({
            src: $("#datatable"),
            sAjaxSource: "<?php echo getUrl('product/home/getList');?>",
            aoColumnDefs : [{
                'bSortable' : false,
                'aTargets' : [0,1,2,3,4,8,9,10]
            }]
        });
        $('[dp]').not("[noinit]").datepicker({
            changeMonth: true,
            autoclose: true,
            format: "yyyy-mm-dd",
            language: 'zh-CN'
        });

    });
</script>
<script type="text/javascript">
    $(function () {
        $(".group").select2();

        $('.confirm').click(function(){
            var id =$(".productBox:checked");
            var type = $(this).attr('attr');
            if(id.length == 0){
                show_message({status:0, message:'请选择商品'});
                return false;
            }
            var type_str = '上架';
            var botton = 'batchPlus';
            if(type == 2){
                type_str = '下架';
                botton = 'batchMinus';
            }
            var message = '确认将'+id.length+'件商品'+type_str;

            $('.save').attr('id', botton);
            $('#model-msg').text(message);
            $('#model-modal-msg').removeClass('hide');
            $('#model-modal-msg').modal();
        });

        $("#batchPlus").live("click",function(){

            var id =$(".productBox:checked");
            if(id.length == 0){
                show_message({status:0, message:'请选择商品'});
                return false;
            }
            var ids = [];
            id.each(function(){
                ids.push($(this).val())
            });
            var index = layer.load(1, {
                shade: [0.1,'#fff']
            });
            $.post("<?php echo getUrl('product/home/bitchChangeStatus') ?>",{ids:ids.join(','),status:2},function (res) {
                $('#datatable').dataTable().fnDraw();
                layer.closeAll();
                $('#model-modal-msg').addClass('hide');
                window.location.reload();
            },'json')
        })

        $("#batchMinus").live("click",function(){

            var id =$(".productBox:checked");
            if(id.length == 0){
                show_message({status:0, message:'请选择商品'});
                return false;
            }
            var ids = [];
            id.each(function(){
                ids.push($(this).val())
            });
            var index = layer.load(1, {
                shade: [0.1,'#fff']
            });
            $.post("<?php echo getUrl('product/home/bitchChangeStatus') ?>",{ids:ids.join(','),status:1},function (res) {
                $('#datatable').dataTable().fnDraw();
                layer.closeAll();
                $('#model-modal-msg').addClass('hide');
                window.location.reload();

            },'json')
        })
    });
</script>
</body>
</html>